package com.winsomely.leecode;

/**
 * 只出现一次的数字
 * 
 * @author liujiawei
 *
 */
public class SingleNumber {

	private static char[] dz = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
			'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };

	private static int radix = 26;

	// Z
	public String convertToTitle(int n) {
		if (n <= 0) {
			return "";
		}
		n--;
		char[] result = new char[33];
		int index = 32;
		while (n >= radix) {
			result[index--] = dz[n % radix];
			n = n / radix - 1;
		}
		result[index] = dz[n];
		return new String(result, index, 33 - index);
	}

	public static void main(String[] args) {
		SingleNumber t = new SingleNumber();
		// int[] nums = { 1, 2, 3, 4, 4, 2, 3, 1, 7 };
		System.out.println(Integer.toString(1, 26));
		System.out.println(t.convertToTitle(1));
	}

}
